﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Threading;
using System.Globalization;

namespace RedHouse.Web.Services
{
    /// <summary>
    /// Summary description for LanguageService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class LanguageService : System.Web.Services.WebService
    {

        [WebMethod]
        public string SwitchLanguage()
        {
            if (Session["Culture"] == null || Session["Culture"].ToString() == "vi-VN")
            {
                //Session["Culture"] = "en-US";
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                ///<remarks>
                ///Saving the current thread's culture set by the User in the Session
                ///so that it can be used across the pages in the current application.
                ///</remarks>
                Session["UICulture"] = Thread.CurrentThread.CurrentUICulture;
                Session["Culture"] = "en-US";
                return "Tiếng Việt";
            }
            else
            {
                //Session["Culture"] = "vi-VN";
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("vi-VN");
                Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN");
                ///<remarks>
                ///Saving the current thread's culture set by the User in the Session
                ///so that it can be used across the pages in the current application.
                ///</remarks>
                Session["UICulture"] = Thread.CurrentThread.CurrentUICulture;
                Session["Culture"] = "vi-VN";
                return "English";
            }
        }
    }
}
